import axios from "axios";
const _axios = axios.create({
    baseURL: "http://localhost:1515",
    withCredentials: true
});

_axios.interceptors.request.use(
    function (config) {
        // 添加headers
        config.headers = {
            Authorization: 'aaa'
        }
        return config;
    },
    function (error) {
        return Promise.reject(error);
    }
);
_axios.interceptors.response.use(
    function (response) {
        // 正确的执行
        return response;
    },
    function (error) {
        if (error?.response?.status === 400) {
            return Promise.resolve("请求参数不对");
        } else if (error?.response?.status === 401) {
            return Promise.resolve("权限不正确");
        }
        else if (error?.response?.status === 403) {
            return Promise.resolve("验证不通过");
        }
        else if (error?.response?.status === 404) {
            return Promise.resolve("资源没有找到");
        }
        else if (error?.response?.status === 405) {
            return Promise.resolve("请求方法不对");
        } else if (error?.response?.status === 500) {
            return Promise.resolve("服务器错误");
        }
    }
);

export default _axios;